package com.ark.cloud.javacallnative.jni;

import com.ark.cloud.javacallnative.entity.*;
import com.ark.cloud.javacallnative.service.*;

import java.util.ArrayList;

/**
 * Copyright(c): 2021 Cloud-Ark Inc.
 * Author(s): Ma Wei (mawei@cloud-ark.com)
 */
public class JNICallNative {

    static {
        System.loadLibrary("JNICallNative");
    }

    /*
     * 功能 ：SDK 初始化函数
     * 参数 ：无
     * 返回值 ：成功返回 0 ，失败返回 -1
     * 初始化时调用
     */
    public native static int DataBus_Init();

    /*
     * 功能 ：SDK  Start
     * 参数 ：无
     * 返回值 ：成功返回 0 ，失败返回 -1_
     *
     */
    public native static int DataBus_Start();

    /*
     * 功能 ：SDK 反初始化函数
     * 参数 ：无
     * 返回值 ：成功返回 0 ，失败返回 -1_
     * 退出时调用
     *
     */
    public native static int DataBus_UnInit();

    // 注册kafka 中间件服务器
    public native static int DataBus_Register_Servers(ArrayList<ServerInfo> ServerArray);


    public native static int DataBus_Register_Subscribe_List(ArrayList<String> StructArray);

    public native static int DataBus_Register_Publish_List(ArrayList<String> StructArray);

//    =====================================================================================
//    =====================================================================================
//    =====================================================================================

    /*
     * 功能 ：注册消息处理类
     * 参数 ：
     * 参数1 MsgHandler: 消息处理类 ,需要用户继承SDK 中 的CMsgDeal 类
     *
     */
    public native static int DataBus_RegisterMsgHandler(MsgHandler msgHandler, long llUser);


    // 平台数据回调
    public native static int  DataBus_Register_PlatState_Handler(OnPlatState msgFunc, long llUser);

// 传感器数据回调

    public native static int DataBus_Register_Sensor_Handler(OnSensorData msgFunc, long llUser);

    // 变轨命令数据回调
    public native static int DataBus_Register_BGCMD_Handler(OnBGCMD msgFunc, long llUser);

    // 事件回调
    public native static int DataBus_Register_Eevent_Handler(OnEvent msgFunc, long llUser);

    // 命令回调
    public native static int DataBus_Register_Cmd_Handler(OnCmd msgFunc , long llUser);
    // 想定回调
    public native static int DataBus_Register_Scenario_Handler(OnScenario msgFunc, long llUser);
// 目标回调

    public native static int DataBus_Register_ContactState_Handler(OnContactState msgFunc, long llUser);

// 时统回调

    public native static int DataBus_Register_ScenarioState_Handler(OnScenarioState msgFunc, long llUser);

    // 轨道回调
    public native static int DataBus_Register_SatOrbit_Handler(OnSatOrbit msgFunc, long llUser);


    ////////////////////////////////////////////////////////////////////////////////////////////////////
//***************************   数据发送    **********************************************************
    //***************************   数据发送    **********************************************************
    //***************************   数据发送    **********************************************************
//////////////////////////////////////////////////////////////////////////////////////////////////////

    // 4.1 平台数据(PlatState)
    public native static int DataBus_SendMsg_PlatState(PlatState platState);

    public native static int DataBus_SendMsg_PlatStateArray(ArrayList<PlatState> platStateArray);

    // 4.2 传感器数据(SensorData)
    public native static int DataBus_SendMsg_SensorObj(SensorData sensorData);

    public native static int DataBus_SendMsg_SensorArray(ArrayList<SensorData> sensorDataArray);

    // 4.3 时统(ScenarioState)
    public native static int DataBus_SendMsg_ScenarioState(ScenarioState scenarioState);

    // 4.5 卫星轨道数据
    public native static int   DataBus_SendMsg_SatOrbit(SatOrbit satOrbit);
    // 4.5 卫星轨道数据
    public native static int DataBus_SendMsg_SatOrbitArray(ArrayList<SatOrbit>  satOrbitArray);


    // 4.4  目标数据（ContactState）
    public native static int DataBus_SendMsg_ContactState(ContactState contactState);

    public native static int DataBus_SendMsg_ContactState_Array(ArrayList<ContactState> contactStateArray);

    //5.1 开火事件(FireEvent)
    public native static int DataBus_SendMsg_FireEvent(FireEvent firezEvent);

    public native static int DataBus_SendMsg_FireEventArray(ArrayList<FireEvent> firezEventArray);

    // 5.2 爆炸事件(ExplodeEvent)
    public native static int DataBus_SendMsg_ExplodeEvent(ExplodeEvent explodeEvent);

    public native static int DataBus_SendMsg_ExplodeEventArray(ArrayList<ExplodeEvent> explodeEventArray);

    // 5.3 探测成功事件(DetectEvent)
    public native static int DataBus_SendMsg_DetectEvent(DetectEvent detectEvent);

    public native static int DataBus_SendMsg_DetectEventArray(ArrayList<DetectEvent> detectEventArray);

    // 5.4 变轨事件(BGCMD)
    public native static int DataBus_SendMsg_BGCMD(BGCMD bgCmd);

    public native static int DataBus_SendMsg_BGCMD_Array(ArrayList<BGCMD> bgCmdArray);

    // 5.5 传感器开/关机(事件/指令)( SensorOnOffEvent)
    public native static int DataBus_SendMsg_SensorOnOffEvent(SensorOnOffEvent turnOnOffEvent);

    public native static int DataBus_SendMsg_SensorOnOffEventArray(ArrayList<SensorOnOffEvent> TurnOnOffEventArray);

    // 5.6 通信事件(CommunicationEvent)
    public native static int DataBus_SendMsg_CommunicationEvent(CommunicationEvent ComuEvent);

    public native static int DataBus_SendMsg_CommunicationEventArray(ArrayList<CommunicationEvent> CommuEventArray);

    // 5.7 平台销毁事件(DestoryEvent)
    public native static int DataBus_SendMsg_DestoryEvent(DestoryEvent destoryEvent);

    public native static int DataBus_SendMsg_DestoryEventArray(ArrayList<DestoryEvent> DestoryEventArray);

    // 5.8 仿真引擎状态变化事件（SimEngineState）
    public native static int DataBus_SendMsg_SimEngineState(SimEngineState event);

    public native static int DataBus_SendMsg_SimEngineState_Array(ArrayList<SimEngineState> eventArray);

    // 5.9 飞机状态变化事件(AircraftStatus)
    public native static int DataBus_SendMsg_AircraftStatus(AircraftStatus event);

    public native static int DataBus_SendMsg_AircraftStatus_Array(ArrayList<AircraftStatus> eventArray);

    // 5.10 干扰事件(JammerEvent)
    public native static int DataBus_SendMsg_JammerEvent(JammerEvent jammerEvent);

    public native static int DataBus_SendMsg_JammerEvent_Array(ArrayList<JammerEvent> eventArray);

    // 5.11  JG开火事件(FireJGEvent)
    public native static int DataBus_SendMsg_FireJGEvent(FireJGEvent event);

    public native static int DataBus_SendMsg_FireJGEvent_Array(ArrayList<FireJGEvent> eventArray);

    // 5.12 DN开火事件(FireDNEvent)
    public native static int DataBus_SendMsg_FireDNEvent(FireDNEvent  event);

    public native static int DataBus_SendMsg_FireDNEvent_Array(ArrayList<FireDNEvent> eventArray);

    // 5.13  JG开火事件(FireCKEvent)
    public native static int DataBus_SendMsg_FireCKEvent(FireCKEvent event);

    public native static int DataBus_SendMsg_FireCKEvent_Array(ArrayList<FireCKEvent> eventArray);

    // 5.14  CK开火事件(EndGameJGEvent)
    public native static int DataBus_SendMsg_EndGameJGEvent(EndGameJGEvent  event);

    public native static int DataBus_SendMsg_EndGameJGEvent_Array(ArrayList<EndGameJGEvent> eventArray);

    // 5.15 DN命中/错过目标事件(EndGameDNEvent)
    public native static int DataBus_SendMsg_EndGameDNEvent(EndGameDNEvent event);

    public native static int DataBus_SendMsg_EndGameDNEvent_Array(ArrayList<EndGameDNEvent> eventArray);

    //5.16 CK命中/错过目标事件(EndGameCKEvent)
    public native static int DataBus_SendMsg_EndGameCKEvent(EndGameCKEvent event);

    public native static int DataBus_SendMsg_EndGameCKEvent_Array(ArrayList<EndGameCKEvent> eventArray);

    // 6.1 指令确认反馈（ReplyCmd）
    public native static int DataBus_SendMsg_ReplyCmd(ReplyCmd event);

    public native static int DataBus_SendMsg_ReplyCmd_Array(ArrayList<ReplyCmd> eventArray);

    //  6.3 飞机起/降指令(AircraftLaunchCmd)
    public native static int DataBus_SendMsg_AircraftLaunchCmd(AircraftLaunchCmd event);

    public native static int DataBus_SendMsg_AircraftLaunchCmd_Array(ArrayList<AircraftLaunchCmd> eventArray);

    // 6.4 速度控制指令（SpeedCmd）
    public native static int DataBus_SendMsg_SpeedCmd(SpeedCmd event);

    public native static int DataBus_SendMsg_SpeedCmd_Array(ArrayList<SpeedCmd> eventArray);

    // 6.5 航线指令（WaypointCmd）
    public native static int DataBus_SendMsg_WaypointCmd(WaypointCmd waypointCmd);

    public native static int DataBus_SendMsg_WaypointCmd_Array(ArrayList<WaypointCmd> eventArray);

    // 6.6 干扰指令（JammerCmd）
    public native static int DataBus_SendMsg_JammerCmd(JammerCmd event);

    public native static int DataBus_SendMsg_JammerCmd_Array(ArrayList<JammerCmd> eventArray);

    // 6.7 引导指令（GuideCmd）
    public native static int DataBus_SendMsg_GuideCmd(GuideCmd event);

    public native static int DataBus_SendMsg_GuideCmd_Array(ArrayList<GuideCmd> eventArray);

    // 6.8 LuaCmd指令（LuaCmd）
    public native static int DataBus_SendMsg_LuaCmd(LuaCmd event);

    public native static int DataBus_SendMsg_LuaCmd_Array(ArrayList<LuaCmd> eventArray);

    // 6.9 LuaCmdReply
    public native static int DataBus_SendMsg_LuaCmdReply(LuaCmdReply event);

    public native static int DataBus_SendMsg_LuaCmdReply_Array(ArrayList<LuaCmd> eventArray);

    //6.10   侦察指令 ReconnoiterCmd
    public native static int DataBus_SendMsg_ReconnoiterCmd(ReconnoiterCmd event);

    public native static int DataBus_SendMsg_ReconnoiterCmd_Array(ArrayList<ReconnoiterCmd> eventArray);

    //6.11   JG打击指令(FireJGCmd)
    public native static int DataBus_SendMsg_FireJGCmd(FireJGCmd event);

    public native static int DataBus_SendMsg_FireJGCmd_Array(ArrayList<FireJGCmd>  eventArray);

    //6.12   侦察指令 FireDNCmd
    public native static int DataBus_SendMsg_FireDNCmd(FireDNCmd event);

    public native static int DataBus_SendMsg_FireDNCmd_Array(ArrayList<FireDNCmd> eventArray);

    //6.13   侦察指令 FireCKCmd
    public native static int DataBus_SendMsg_FireCKCmd(FireCKCmd event);

    public native static int DataBus_SendMsg_FireCKCmd_Array(ArrayList<FireCKCmd>  eventArray);

    //6.14   侦察指令 SatlliteCmd
    public native static  int  DataBus_SendMsg_SatelliteCmd(SatelliteCmd event);

    public native static  int   DataBus_SendMsg_SatelliteCmd_Array(ArrayList<SatelliteCmd>  eventArray);

    // 想定
    public native static int DataBus_SendMsg_ScenarioData(ScenarioData scenarioData);


    ////////////////////////////////////////////////////////////////////////////////////////////////////
//***************************  数据解析    **********************************************************
//////////////////////////////////////////////////////////////////////////////////////////////////////
// 4.1 平台数据(PlatState)
    public native static boolean DataBus_PlateState(String pDataBuf, int nDataLen, PlatState plateState);

    public native static boolean DataBus_PlateState_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<PlatState> plateStateArray);

    // 4.2 传感器数据(SensorData)
    public native static boolean DataBus_SensorData(String pDataBuf, int nDataLen, SensorData sensorData);

    public native static boolean DataBus_SensorData_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<SensorData> DataArray);

    // 4.3 时统(ScenarioState)
    public native static boolean DataBus_ScenarioState(String pDataBuf, int nDataLen, ScenarioState scenarioState);

    // 4.4  目标数据（ContactState）
    public native static boolean DataBus_ContactState(String pDataBuf, int nDataLen, ContactState contactState);

    public native static boolean DataBus_ContactState_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<ContactState> contactStateArray);

    // 4.5  卫星轨道数据（SatOrbit）
    public native static boolean DataBus_SatOrbit(String pDataBuf, int nDataLen, SatOrbit satOrbit);

    public native static boolean DataBus_SatOrbit_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<SatOrbit> satOrbitArray);

    //5.1 开火事件(FireEvent)
    public native static boolean DataBus_FireEvent(String pDataBuf, int nDataLen, FireEvent fireEvent);

    public native static boolean DataBus_FireEvent_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<FireEvent> FireEventArray);

    // 5.2 爆炸事件(ExplodeEvent)
    public native static boolean DataBus_ExplodeEvent(String pDataBuf, int nDataLen, ExplodeEvent eEvent);

    public native static boolean DataBus_ExplodeEvent_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<ExplodeEvent> ExplodeEventArray);

    // 5.3 探测成功事件(DetectEvent)
    public native static boolean DataBus_DetectEvent(String pDataBuf, int nDataLen, DetectEvent dectEvent);

    public native static boolean DataBus_DetectEvent_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<DetectEvent> EventArray);

    // 5.4 变轨事件(BGCMD)
    public native static boolean DataBus_BGCMD(String pDataBuf, int nDataLen, BGCMD bgCmd);

    public native static boolean DataBus_BGCMD_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<BGCMD> CmdArray);

    // 5.5 传感器开/关机(事件/指令)( SensorOnOffEvent)
    public native static boolean DataBus_SensorOnOffEvent(String pDataBuf, int nDataLen, SensorOnOffEvent event);

    public native static boolean DataBus_SensorOnOffEvent_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<SensorOnOffEvent> eventArray);

    // 5.6 通信事件(CommunicationEvent)
    public native static boolean DataBus_CommunicationEvent(String pDataBuf, int nDataLen, CommunicationEvent event);

    public native static boolean DataBus_CommunicationEvent_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<CommunicationEvent> eventArray);

    // 5.7 平台销毁事件(DestoryEvent)
    public native static boolean DataBus_DestoryEvent(String pDataBuf, int nDataLen, DestoryEvent event);

    public native static boolean DataBus_DestoryEvent_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<DestoryEvent> eventArray);

    // 5.8 仿真引擎状态变化事件（SimEngineState）
    public native static boolean DataBus_SimEngineState(String pDataBuf, int nDataLen, SimEngineState event);

    public native static boolean DataBus_SimEngineState_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<SimEngineState> eventArray);

    // 5.9 飞机状态变化事件(AircraftStatus)
    public native static boolean DataBus_AircraftStatus(String pDataBuf, int nDataLen, AircraftStatus event);

    public native static boolean DataBus_AircraftStatus_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<AircraftStatus> eventArray);

    // 5.10 干扰事件(JammerEvent)
    public native static boolean DataBus_JammerEvent(String pDataBuf, int nDataLen, JammerEvent event);

    public native static boolean DataBus_JammerEvent_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<JammerEvent> eventArray);

    // 5.11 JG开火事件(FireJGEvent)
    public native static boolean  DataBus_FireJGEvent(String pDataBuf, int nDataLen, FireJGEvent event);
    public native static boolean   DataBus_FireJGEvent_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<FireJGEvent>  eventArray);

    // 5.12 DN开火事件(FireDNEvent)
    public native static boolean   DataBus_FireDNEvent(String pDataBuf, int nDataLen, FireDNEvent  event);
    public native static boolean DataBus_FireDNEvent_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<FireDNEvent>   eventArray);

    // 5.13 CK开火事件(FireCKEvent)
    public native static boolean   DataBus_FireCKEvent(String pDataBuf, int nDataLen, FireCKEvent  event);
    public native static boolean  DataBus_FireCKEvent_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<FireCKEvent>  eventArray);

    // 5.14 JG开火事件(EndGameJGEvent)
    public native static boolean  DataBus_EndGameJGEvent(String pDataBuf, int nDataLen, EndGameJGEvent  event);
    public native static boolean  DataBus_EndGameJGEvent_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<EndGameJGEvent>  eventArray);

    // 5.15 DN命中/错过目标事件(EndGameDNEvent)
    public native static boolean  DataBus_EndGameDNEvent(String pDataBuf, int nDataLen, EndGameDNEvent  event);
    public native static boolean DataBus_EndGameDNEvent_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<EndGameDNEvent>   eventArray);

    // 5.16 CK命中/错过目标事件(EndGameCKEvent)
    public native static boolean  DataBus_EndGameCKEvent(String pDataBuf, int nDataLen, EndGameCKEvent  event);
    public native static boolean  DataBus_EndGameCKEvent_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<EndGameCKEvent>   eventArray);

    // 6.1 指令确认反馈（ReplyCmd）
    public native static boolean DataBus_ReplyCmd(String pDataBuf, int nDataLen, ReplyCmd event);

    public native static boolean DataBus_ReplyCmd_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<ReplyCmd> eventArray);

    //  6.3 飞机起/降指令(AircraftLaunchCmd)
    public native static boolean DataBus_AircraftLaunchCmd(String pDataBuf, int nDataLen, AircraftLaunchCmd event);

    public native static boolean DataBus_AircraftLaunchCmd_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<AircraftLaunchCmd> eventArray);

    // 6.4 速度控制指令（SpeedCmd）
    public native static boolean DataBus_SpeedCmd(String pDataBuf, int nDataLen, SpeedCmd event);

    public native static boolean DataBus_SpeedCmd_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<SpeedCmd> eventArray);

    // 6.5 航线指令（WaypointCmd）
    public native static boolean DataBus_WaypointCmd(String pDataBuf, int nDataLen, WaypointCmd event);

    public native static boolean DataBus_WaypointCmd_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<WaypointCmd> eventArray);

    // 6.6 干扰指令（JammerCmd）
    public native static boolean DataBus_JammerCmd(String pDataBuf, int nDataLen, JammerCmd event);

    public native static boolean DataBus_JammerCmd_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<JammerCmd> eventArray);

    // 6.7 引导指令（GuideCmd）
    public native static boolean DataBus_GuideCmd(String pDataBuf, int nDataLen, GuideCmd event);

    public native static boolean DataBus_GuideCmd_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<GuideCmd> eventArray);

    // 6.8 LuaCmd指令（LuaCmd）
    public native static boolean DataBus_LuaCmd(String pDataBuf, int nDataLen, LuaCmd event);

    public native static boolean DataBus_LuaCmd_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<LuaCmd> eventArray);

    // 6.9 LuaCmdReply
    public native static boolean DataBus_LuaCmdReply(String pDataBuf, int nDataLen, LuaCmdReply event);

    public native static boolean DataBus_LuaCmdReply_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<LuaCmdReply> eventArray);

    // 6.10 ReconnoiterCmd
    public native static boolean DataBus_ReconnoiterCmd(String pDataBuf, int nDataLen, ReconnoiterCmd event);

    public native static boolean DataBus_ReconnoiterCmd_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<ReconnoiterCmd> eventArray);

    // 6.11 FireJGCmd
    public native static boolean DataBus_FireJGCmd(String pDataBuf, int nDataLen, FireJGCmd   cmd);

    public native static boolean DataBus_FireJGCmd_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<FireJGCmd>   cmdArray);


    // 6.12 FireDNCmd
    public native static boolean DataBus_FireDNCmd(String pDataBuf, int nDataLen, FireDNCmd   cmd);

    public native static boolean DataBus_FireDNCmd_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<FireDNCmd>  cmdArray);

    // 6.13 FireCKCmd
    public native static boolean DataBus_FireCKCmd(String pDataBuf, int nDataLen, FireCKCmd   cmd);

    public native static boolean DataBus_FireCKCmd_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<FireCKCmd>  cmdArray);


    // 6.14 SatelliteCmd
    public native static boolean DataBus_SatelliteCmd(String pDataBuf, int nDataLen, SatelliteCmd   cmd);

    public native static boolean DataBus_SatelliteCmd_Array(String pDataBuf, int nDataLen, int nStructNum, ArrayList<SatelliteCmd>  cmdArray);

    public native static int DataBus_ScenarioData(String pDataBuf, int nDataLen, ScenarioData scenarioData);

    /***
     * 功能 ：写日志
     * 参数：
     * 参数1 nLogLevel   ：日志类型
     * TRACE_LOG = 0,
     * DEBUG_LOG = 1
     * INFO_LOG =  2,
     * ERROR_LOG = 3,
     * FATAL_LOG = 4,
     * 参数2 sLogInfo  :日志内容
     * 返回值： 成功时返回 0 ，失败时返回 -1
     ****/
    public native static int DataBus_WriteLog(int nLogLevel, String sLogInfo);
}
